package com.sc.nft.entity.vo;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.sc.nft.enums.ChainStatusEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;

@Data
public class UserHoldCollectionVO {

    @ApiModelProperty("用户藏品id")
    private Long userCollectionId;

    @ApiModelProperty("藏品id")
    private Long collectionId;

    @ApiModelProperty("编号")
    private String numbering;

    @ApiModelProperty("藏品图片")
    private String collectionImage;

    @ApiModelProperty("买入价")
    private String buyPrice;

    @ApiModelProperty("NONE:上链中,ONLINE:已上链(此状态下可以选择),OFFLINE:销毁,FAIL:上链失败,DEAL:已转移")
    private ChainStatusEnum status;

    @ApiModelProperty("是否锁仓")
    private Boolean isLockedPosition=Boolean.FALSE;

    @ApiModelProperty("锁仓描述")
    private String lockedPositionDescribe;

    @ApiModelProperty("锁仓到期日期")
    @JsonIgnore
    private Date lockedPositionTime;


    public void setLockedPositionTime(Date lockedPositionTime) {
        this.lockedPositionTime=lockedPositionTime;
        // 当前日期大于锁仓日期,那么就是已经到期了 是否锁仓字段给false.如果小于的话,给true.并且说明 锁仓到期时间
        if (lockedPositionTime != null) {
            if (this.lockedPositionTime.getTime() < System.currentTimeMillis()) {
                this.isLockedPosition = false;
                this.lockedPositionDescribe = "锁仓已到期";
            } else {
                this.isLockedPosition = true;
                this.lockedPositionDescribe = StrUtil.format("锁仓结束时间: {}", DateUtil.format(this.lockedPositionTime, "yyyy-MM-dd HH:mm:ss"));
            }
        } else {
            this.isLockedPosition = false;
        }
    }
    public void setBuyPrice(BigDecimal buyPrice) {
        this.buyPrice = buyPrice.setScale(2,BigDecimal.ROUND_DOWN).toPlainString();
    }
}
